<html><title>An example of using layers to follow an object</title>
<head>

<script language="Javascript" src="../gamelib/gamelib_core.js"></script>
<script language="Javascript" src="../gamelib/gamelib_mouse.js"></script>
<script language="Javascript" src="../gamelib/gamelib_sprites.js"></script>

<script language="Javascript">

var mycounter=0;

function init(){
	Sp_linuxcompatible=true;
	penguin=new Sp_Sprite();
	penguin.setImage("../images/penguin.gif",64,64,11,2);
	penguin.setXlimits(0,1000);
	penguin.setYlimits(0,1000);
	penguin.moveTo(120,320);
	penguin.setFrame(1);
	penguin.setAnimationSpeed(3,"forward");
	penguin.setDir(1,0);
	penguin.setSpeed(4);
	penguin.switchOn();

	mylayer=new Gl_layer(0,0,200,'<table width=250 height=150 cellpadding=0 cellspacing=0 border=0><tr><td height=150 width=250><center><font color="#ffffff" face="Arial" size=5>This layer will follow the sprite for a while...</font></center></td></tr></table>');
	mylayer.setXlimits(-100,600);
	mylayer.setYlimits(-100,600);
	mylayer.setBackground("../images/lback0.gif"); // example of setting background image
	mylayer.resizeTo(250,150);		    // example of sizing a layer exactly

	mymouse=Ms_initmouse();
	mylayer.follow(penguin,-100,-160);

	Gl_scrollbars("no");
	Gl_hook("test()");
	Gl_start();
}

function test(){
	if(mycounter++==50){
		penguin.setDir(0,-1);
		penguin.setFrame(2)
	}else if(mycounter==100){
		penguin.setDir(-1,0);
		penguin.setFrame(0)
	}else if(mycounter==150){
		penguin.setDir(0,1);
		penguin.setFrame(3)
	}else if(mycounter==200){
		penguin.setDir(1,0);
		penguin.setFrame(1);
		mycounter=0
	}
	if(Gl_ticker==70){
		mylayer.stopFollowing();
		mylayer.makeDraggable();
		mylayer.write('<table width=250 height=150 cellpadding=0 cellspacing=0 border=0><tr><td height=150 width=250><center><font color="#ffffff" face="Arial" size=5>And now it\'s had enough, and has stopped following :)<br><font size=1>You can drag it now!</font></font></center></td></tr></table>')
	}
}

</script>
</head>

<body bgcolor="#000000" onload="init()" style="overflow:hidden">
<font color="#ffbb00" face="Arial" size=3>
<u>Layer library example 2</u><br><br>
<font size=2>
The layer is following the sprite, using the .follow() method.<br>
Could be handy for speech balloons or whatever! When it stops<br>
you can drag it around too!
</font>
</font>
</body>

</html>